package com.spiro;

import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Scanner;

/**
 * Created by Administrator on 2016/10/17 0017.
 */
public class SimpleApiTest {

    public static final Logger LOG = LoggerFactory.getLogger(SimpleApiTest.class);

    public static void main(String[] args) throws IOException {
        ZooKeeper zooKeeper = null;

        try {
            zooKeeper = new ZooKeeper("192.168.103.108:2181", 10000, new Watcher() {
                public void process(WatchedEvent event) {
                    LOG.info(event.toString());
                }
            });

            zooKeeper.getData("/aa", new Watcher() {
                public void process(WatchedEvent event) {
                    LOG.info(event.toString());
                }
            }, new AsyncCallback.DataCallback() {
                public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {

                    LOG.info("rc={}, path={}, ctx={}, stat={}", new Object[] {rc, path, ctx, stat});
                    if (stat == null) {

                    }


                }
            }, null);

            Scanner scanner = new Scanner(System.in);
            String line = scanner.next();
        } finally {
            if (zooKeeper != null) {
                try {
                    zooKeeper.close();
                } catch (InterruptedException e) {
                }
            }
        }


    }
}
